package singlewindow;

import guiclient.Application;
import guicommon.controls.*;
import guicommon.controls.handlers.*;
import java.awt.Color;
import java.io.IOException;

public class SingleWindow extends Application{

    private static SingleWindow instance;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        instance = new SingleWindow();
        instance.Show();
    }

    private Window window;
    private Button button;
    private TextBox textBox;

    private SingleWindow() throws IOException {
        window = new Window();
        window.SetSize(300, 200);
        window.SetPoint(50, 100);
        window.SetTitle("Test application");
        window.SetBackGround(Color.white);
        RegisterControl(window);

        textBox = new TextBox();
        textBox.SetSize(150, 20);
        textBox.SetPoint(80, 100);
        textBox.SetOwner(window);
        textBox.SetText("");
        textBox.SetBackGround(Color.white);
        textBox.SetKeyPressedEventHandler(new KeyPressedEventHandler() {

            @Override
            public void Event(Control sender, KeyEventArgs args) {
                if (args.IsPressed()) {
                    String text = textBox.GetText();
                    text = text + args.GetKey();
                    textBox.SetText(text);
                }
            }
        });
        RegisterControl(textBox);

        button = new Button();
        button.SetSize(70, 20);
        button.SetPoint(115, 130);
        button.SetOwner(window);
        //button.SetBackGround(Color.red);
        button.SetText("Clear text");
        button.SetMouseClickedEventHandler(new MouseClickedEventHandler() {

            @Override
            public void Event(Control sender, MouseEventArgs args) {
                textBox.SetText("");
            }
        });
        RegisterControl(button);
    }
    
}
